# -*- coding: utf-8
import io

from django.http import HttpResponse
from django.shortcuts import render
import datetime

from django.views import View


def hello(request):
    return HttpResponse("Hello world ! ")


def hello2(request):
    context = {}
    context['hello'] = 'Hello World!'
    return render(request, 'hello.html', context)  # render 将数据渲染到模板文件上


def hello3(request):
    context = {}
    context['helloList'] = ["列表1", "列表2", "列表3"]
    return render(request, 'hello.html', context)  # render 将数据渲染到模板文件上


def hello4(request):
    views_dict = {"name": "字典"}
    return render(request, "hello.html", {"views_dict": views_dict})


def hello5(request):
    now = datetime.datetime.now()  # 获取当前时间
    return render(request, "hello.html", {"time": now})


def hello6(request):
    views_str = "<a href='https://www.baidu.com/'>点击跳转</a>"
    return render(request, "hello.html", {"views_str": views_str})


def hello7(request):
    views_list = ["列表1", "列表2", "列表3", "列表4", ]
    return render(request, "hello.html", {"views_list": views_list})


def hello8(request):
    name = "模板继承"
    return render(request, "children.html", {"name": name})


class Login(View):

    def get(self, request):
        return HttpResponse("GET 方法")

    def post(self, request):
        user = request.POST.get("user")
        pwd = request.POST.get("pwd")
        if user == "zhw" and pwd == "123456":
            return HttpResponse("POST 方法")
        else:
            return HttpResponse("POST 方法 1")


def verifycodeValid(request):
    vc = request.POST['vc']
    if vc.upper() == request.session['verifycode']:
        return HttpResponse('ok')
    else:
        return HttpResponse('no')
